<?php

/**
 * This is the model class for table "user_upload_file".
 *
 * The followings are the available columns in table 'user_upload_file':
 * @property string $id
 * @property string $bucket
 * @property string $user_id
 * @property string $file_name
 * @property string $image_type
 * @property double $image_width
 * @property double $image_height
 * @property string $sign
 * @property string $upload_time
 */
class UserUploadFile extends CActiveRecord
{

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return '{{user_upload_file}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('sign, upload_time', 'required'),
            array('image_width, image_height', 'numerical'),
            array('user_id, upload_time', 'length', 'max' => 10),
            array('file_name', 'length', 'max' => 200),
            array('image_type', 'length', 'max' => 20),
            array('sign', 'length', 'max' => 50),
            array('bucket', 'length', 'max' => 50),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('id, bucket, user_id, file_name, image_type, image_width, image_height, sign, upload_time', 'safe'),
            array('id, bucket, user_id, file_name, image_type, image_width, image_height, sign, upload_time', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'bucket' => '空间名称',
            'user_id' => '用户id',
            'file_name' => 'upyun路径',
            'image_type' => '图片类型',
            'image_width' => '图片高度',
            'image_height' => '图片宽度',
            'sign' => '签名',
            'upload_time' => '上传时间',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     *
     * Typical usecase:
     * - Initialize the model fields with values from filter form.
     * - Execute this method to get CActiveDataProvider instance which will filter
     * models according to data in model fields.
     * - Pass data provider to CGridView, CListView or any similar widget.
     *
     * @return CActiveDataProvider the data provider that can return the models
     * based on the search/filter conditions.
     */
    public function search()
    {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('bucket', $this->bucket);
        $criteria->compare('user_id', $this->user_id, true);
        $criteria->compare('file_name', $this->file_name, true);
        $criteria->compare('image_type', $this->image_type, true);
        $criteria->compare('image_width', $this->image_width);
        $criteria->compare('image_height', $this->image_height);
        $criteria->compare('sign', $this->sign, true);
        $criteria->compare('upload_time', $this->upload_time, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return UserUploadFile the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function getSearchFormConfig()
    {
        return array(
            'method' => 'get',
            'title' => '查询用户上传列表',
            'class' => 'form',
            'showErrorSummary' => true,
            'showErrors' => true,
            'elements' => array(
                'user_id' => array(
                    'type' => 'text',
//                    'value' => !empty($this->user_id) ? $this->user_id : '',
                    'hint' => '请输入用户id',
                    'enableAjaxValidation' => true,
                ),
                'upload_time' => array(
                    'type' => 'text',
                ),
            ),
            'buttons' => array(
                'submit' => array(
                    'type' => 'submit',
                    'label' => '查 询',
                ),
            ),
        );
    }

    /**
     * 获取空间列表
     * @return type
     */
    public static function getBucketList()
    {
        return array('xkdemo' => '图片空间', 'xkfiles' => '文件空间');
    }

}
